<template>
    <div class="login-container">
        <div class="login-adv">
            <div class="login-adv_title">
                <h2>
                    {{ sysConfig?.pc_name ? sysConfig.pc_name : "tmAdmin" }}
                </h2>
                <h4>优雅 / 简洁 / 高效</h4>
                <p>
                    基于Vue3 + ElementPlus + Nuxt3 + uniapp + Thinkphp8
                    的综合解决方案
                </p>
            </div>
            <div class="login-adv_mask"></div>
        </div>
        <div class="login-main">
            <div class="login-form">
                <div class="login-header">
                    <div class="logo">
                        <img
                            alt="logo"
                            :src="
                                sysConfig?.pc_logo
                                    ? getUrl(sysConfig?.pc_logo)
                                    : '/assets/images/logo.png'
                            "
                        />
                        <label
                            >欢迎使用
                            {{
                                sysConfig?.pc_name
                                    ? sysConfig?.pc_name
                                    : "tmAdmin"
                            }}</label
                        >
                    </div>
                </div>
                <el-tabs>
                    <el-tab-pane label="账号登陆" lazy>
                        <accountForm :isAgreement="isAgreement" />
                    </el-tab-pane>
                    <el-tab-pane label="手机号登陆" lazy>
                        <mobileForm :isAgreement="isAgreement" />
                    </el-tab-pane>
                </el-tabs>
                <div class="login-reg">
                    <div class="flex-1">
                        <el-checkbox v-model="isAgreement" size="small">
                            <span class="text-tx-secondary text-sm">
                                已阅读并同意
                                <NuxtLink
                                    :to="{
                                        path: '/agreement',
                                        query: { type: 1 },
                                    }"
                                    custom
                                    v-slot="{ href }"
                                >
                                    <a
                                        class="text-tx-primary"
                                        :href="href"
                                        target="_blank"
                                    >
                                        《服务协议》
                                    </a>
                                </NuxtLink>
                                和
                                <NuxtLink
                                    class="text-tx-primary"
                                    :to="{
                                        path: '/agreement',
                                        query: { type: 2 },
                                    }"
                                    custom
                                    v-slot="{ href }"
                                >
                                    <a
                                        class="text-tx-primary"
                                        :href="href"
                                        target="_blank"
                                    >
                                        《隐私政策》
                                    </a>
                                </NuxtLink>
                            </span>
                        </el-checkbox>
                    </div>
                    <span>
                        <NuxtLink :to="{ path: '/login/register' }">
                            注册账号
                        </NuxtLink>
                    </span>
                </div>
                <div class="login-other">
                    <div class="title">
                        <span>其他方式登录</span>
                    </div>
                    <div class="content">
                        <div class="item" @click="wechatCodeLogin">
                            <img
                                class="h-[20px] mr-1"
                                src="@/assets/images/wechat.png"
                            />
                            <span>微信扫码登录</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script lang="ts" setup>
import accountForm from "./components/account.vue";
import mobileForm from "./components/mobile.vue";
import { getUrl, getDomain } from "@/utils/common";
import { getWxOpScanCodeUrl } from "@/api/login";
import useConfigStore from "@/stores/config";

definePageMeta({
    layout: false,
    middleware: ["login"],
});

const sysConfig = useConfigStore().sysConfig?.base;

const isAgreement = ref(false);

const wechatCodeLogin = async () => {
    const res = await getWxOpScanCodeUrl({
        url: getDomain() + "/pc/login/wechat",
    });
    window.location.href = res.url;
};

</script>

<style lang="scss" scoped>
.login-container {
    width: 100%;
    height: 100vh;
    background: #fff;
    display: flex;

    .login-adv {
        width: 30%;
        background-color: #555;
        background-size: cover;
        background-position: center center;
        background-repeat: no-repeat;
        position: relative;
        background-image: url("@/assets/images/auth_banner.png");

        .login-adv_title {
            color: #fff;
            padding: 40px;
            position: absolute;
            top: 0px;
            left: 0px;
            right: 0px;
            z-index: 2;

            h2 {
                font-size: 40px;
            }

            h4 {
                font-size: 18px;
                margin-top: 10px;
                font-weight: normal;
            }

            p {
                font-size: 14px;
                margin-top: 10px;
                line-height: 1.8;
                color: rgba(255, 255, 255, 0.6);
            }

            div {
                margin-top: 10px;
                display: flex;
                align-items: center;

                span {
                    margin-right: 15px;
                }

                i {
                    font-size: 40px;
                }

                i.add {
                    font-size: 20px;
                    color: rgba(255, 255, 255, 0.6);
                }
            }
        }

        .login-adv_mask {
            position: absolute;
            top: 0px;
            left: 0px;
            right: 0px;
            bottom: 0px;
            background: rgba(0, 0, 0, 0.5);
            z-index: 1;
        }
    }

    .login-main {
        flex: 1;
        overflow: auto;
        display: flex;

        .login-form {
            width: 400px;
            margin: auto;
            padding: 20px 0;

            .login-header {
                margin-bottom: 15px;

                .logo {
                    display: flex;
                    align-items: center;

                    img {
                        width: 40px;
                        height: 40px;
                        vertical-align: bottom;
                        margin-right: 10px;
                    }

                    label {
                        font-size: 26px;
                        font-weight: bold;
                    }
                }
            }

            .login-reg {
                display: flex;
                font-size: 14px;
                line-height: 24px;
                margin-top: 15px;
                color: var(--el-text-color-primary);

                span {
                    color: var(--el-color-primary);
                    cursor: pointer;
                }

                span:hover {
                    color: var(--el-color-primary-light-3);
                }
            }

            .login-other {
                text-align: center;
                .title {
                    height: 20px;
                    position: relative;
                    margin-top: 20px;
                    margin-bottom: 20px;

                    span {
                        font-size: 14px;
                    }
                }

                .title::before {
                    content: "";
                    width: 120px;
                    height: 1px;
                    background: var(--el-border-color-light);
                    position: absolute;
                    left: 0;
                    top: 10px;
                }

                .title::after {
                    content: "";
                    width: 120px;
                    height: 1px;
                    background: var(--el-border-color-light);
                    position: absolute;
                    right: 0;
                    top: 10px;
                }

                .content {
                    display: flex;
                    justify-content: center;

                    .item {
                        display: flex;
                        justify-content: center;
                        font-size: 13px;
                        cursor: pointer;
                    }
                }
            }
        }

        .login-form:deep(.el-tabs) .el-tabs__header {
            margin-bottom: 25px;
        }

        .login-form:deep(.el-tabs) .el-tabs__header .el-tabs__item {
            font-size: 14px;
        }

        .login-form:deep(.login-forgot) {
            text-align: right;
            color: var(--el-color-primary);
            cursor: pointer;
        }

        .login-form:deep(.login-forgot):hover {
            color: var(--el-color-primary-light-3);
        }
    }
}

@media (max-width: 1200px) {
    .login-form {
        width: 340px;
    }
}

@media (max-width: 1000px) {
    .login-main {
        display: block;
    }

    .login-form {
        width: 100%;
        padding: 20px 40px;
    }

    .login-adv {
        display: none;
    }
}
</style>
